package top.tangyh.lamp.care.service.clickhouse.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import top.tangyh.lamp.care.mapper.IotDataMapper;
import top.tangyh.lamp.care.service.clickhouse.IotDataService;
import top.tangyh.lamp.care.vo.result.IotDataResult;
import top.tangyh.lamp.common.utils.PDateUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author: zqb
 * @date: 2024/11/29 10:23
 */
@Service
@AllArgsConstructor
@Slf4j
@DS("clickhouse")
public class IotDataServiceImpl implements IotDataService {

    private final IotDataMapper iotDataMapper;
    @Override
    public List<IotDataResult> selectHourRecordsByHis(String hospitalNumber, List<String> timePointList) {
        // 使用 Java 的 String.join() 方法将时间点列表拼接成一个适合 SQL 使用的字符串
//        String timePoints = timePointList.stream()
//                .map(time -> "'" + time + "'")  // 每个时间点加上单引号
//                .collect(Collectors.joining(","));
//        List<Long> timePointListLong = new ArrayList<>();
//        for (int i = 0; i <timePointList.size() ; i++) {
//
//            timePointListLong.add(PDateUtils.convertToTimestamp(PDateUtils.convertStringToDate(timePointList.get(i)),"Asia/Shanghai"));
//        }
        List<IotDataResult> listAll=new ArrayList<>();
        for (int i = 0; i <timePointList.size() ; i++) {
            listAll.addAll(iotDataMapper.selectHourRecordsByHisOfOne(hospitalNumber,timePointList.get(i))) ;
        }
       return listAll;
        //return iotDataMapper.selectHourRecordsByHis(hospitalNumber,timePointList);
    }

    @Override
    public List<IotDataResult> getCustomCollectionByHospitalNumberAndTimePoint(String hospitalNumber, List<String> timePointList) {
        List<IotDataResult> listAll=new ArrayList<>();
        for (int i = 0; i <timePointList.size() ; i++) {
            listAll.addAll(iotDataMapper.getCustomCollectionByHospitalNumberAndTimePointOne(hospitalNumber,timePointList.get(i))) ;
        }
        return listAll;
    }

    @Override
    public String selectTimeTest() {
        return iotDataMapper.selectTimeTest();
    }
}
